<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.io.*,java.util.*"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="jakarta.servlet.http.*,java.util.*"%>
<%
    if(session.getAttribute("isRoot").equals("true")){

    }else{
        String site = new String("./invalid.jsp");
        response.setStatus(response.SC_MOVED_TEMPORARILY);
        response.setHeader("location",site);
    }
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.staticfile.org/popper.js/2.9.3/umd/popper.min.js"></script>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
    <!-- Brand -->
    <a class="navbar-brand" href="#">
        ATP
    </a>
    <!-- Links -->
    <ul class="navbar-nav">
        <li class="nav-item">
            <a class="nav-link" href="#">公网博客管理</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">公网博客外链管理</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="#">测试管理</a>
        </li>
    </ul>
</nav>
<%
    final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
    String DB_URL = "jdbc:mysql://localhost/mybatis?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
    final String USER = "root";
    final String PASS = "1122";
    Connection conn = null;
    Statement stmt = null;
    ArrayList<ArrayList<String>> al = new ArrayList<ArrayList<String>>();
    try{
        Class.forName(JDBC_DRIVER);
        conn = DriverManager.getConnection(DB_URL,USER,PASS);
        stmt = conn.createStatement();
        String sql;
        sql = "select name,age from Blog";
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next()){
            String name = rs.getString("name");
            int age = rs.getInt("age");
            ArrayList<String> a = new ArrayList<String>();
            a.add(name);
            a.add(""+age);
            al.add(a);
            System.out.println("name: "+name+"\n"+"age: "+age);
        }
        rs.close();
        stmt.close();
        conn.close();
    } catch(Exception se){
        //Handle errors for JDBC
        se.printStackTrace();
    }//Handle errors for Class.forName
    finally{
        //finally block used to close resources
        try{
            if(stmt!=null)
                stmt.close();
        }catch(SQLException ignored){
        }// nothing we can do
        try{
            if(conn!=null)
                conn.close();
        }catch(SQLException se){
            se.printStackTrace();
        }//end finally try
    }//end try
%>
<table class="table">
    <caption>基本的表格布局</caption>
    <thead>
    <tr>
        <th>名称</th>
        <th>城市</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>Sachin</td>
        <td>Mumbai</td>
    </tr>
    <%for (ArrayList<String> strings : al) {%>
    <tr>
        <td><%=strings.get(0)%>
        </td>
        <td><%=strings.get(0)%>
        </td>
    </tr>
    <%}%>
    </tbody>
</table>
</body>
</html>